<template>
	<base-page class="edit-form base-form" style="width: 100vw" title="学员报名" @back="onCancel">
		<view class="main-box">
			<view class="content-box">
				<u-form ref="mobileApplyInfoRef" :model="formData" label-width="120px" label-align="left"
					:errorType="['border-bottom', 'message']">
					<u-row gutter="0">
						<u-col :span="12">
							<view class="mt-16">
								<view class="u-cell-group" style="padding: 5px">
									<u-row gutter="0">
										<!-- <u-col :span="12">
											<field-input label="姓名" prop="name" v-model="formData.name" type="text"
												:clearable="true" :disabled="false" :required="true"
												:readonly="false" />
										</u-col> -->
										<u-col :span="12">
											<field-select label="班级" prop="classId" v-model="formData.classId"
												:multiple="false" :dataList="classIdWidget" :required="true"
												:disabled="false" />
										</u-col>
										<u-col :span="12">
											<field-select label="干部" prop="officeId" v-model="formData.officerId"
												:multiple="false" :dataList="ganbuWidget" :required="true"
												@change="changeGan" :disabled="false" />
											<!-- <u-radio-group v-model="formData.officerId" @change="changeGan">
												<u-radio shape="circle" v-for="(item, index) in ganbuWidget"
													:key="index" :name="item.name">{{ item.name }}</u-radio>
											</u-radio-group> -->
										</u-col>


									</u-row>
								</view>
							</view>
						</u-col>
					</u-row>
				</u-form>
			</view>
		</view>
		<view class="menu-box">
			<u-button :custom-style="{width: '100%'}" style="flex-grow: 1; margin-left: 8px" type="primary"
				size="medium" @click="onAddClick()">
				提交
			</u-button>
		</view>

		<u-modal v-model="show" :content="content" show-cancel-button  @cancel="goBack()" @confirm="addContinue()" confirm-text="继续添加" cancel-text='返回'></u-modal>
	</base-page>
</template>

<script>
	import {
		showMessage,
	} from '@/utils';
	import {
		SysUserController,
		SchoolInfoController,
		ClassInfoController,
		CourseInfoController,
		StudentInfoController,
		DictionaryController
	} from '@/api';
	import projectConfig from '@/core/config'
	export default {
		name: 'mobileApplyInfo',

		data() {
			return {
				show: false,
				content: '',
				formData: {
					// id
					id: undefined,
					// 班级id
					classId: undefined,
					// 姓名
					name: undefined,

					officerId: undefined,
					// 手机号码
					phone: undefined,

				},
				classIdWidget: [],
				ganbuWidget: [],
				rules: {
					'name': [{
						required: true,
						message: '请输入姓名',
						trigger: 'blur',
						transform: (value) => String(value)
					}],
					'phone': [{
						required: true,
						message: '请输入手机号码',
						trigger: 'blur',
						transform: (value) => String(value)
					}],

					'classId': [{
						required: true,
						message: '请选择班级',
						trigger: 'blur',
						transform: (value) => String(value)
					}],

				},
				fileList: []

			}
		},
		computed() {},
		methods: {
			addContinue(){
				this.formData={
					name:'',
					officerId:'',
				}
				
			},
			goBack() {
				uni.navigateBack();
			},
			loadClassIdDropdownList() {
				const params = {
					filter: {}
				};
				ClassInfoController.listDict(this, params).then(res => {
					this.classIdWidget = res;
				}).catch(e => {
					reject(e);
				});
			},
			loadGanbuDropdownList() {
				const params = {
					filter: {}
				};
				CourseInfoController.mobileList(this, params).then(res => {
					this.ganbuWidget = res;
				}).catch(e => {
					reject(e);
				});
			},
			changeGan(val, val2) {
				this.formData.officerId = val2.id
				this.formData.jobTitle = val2.jobTitle
				this.formData.name = val2.name
				this.formData.phone = val2.phone
			},
			onCancel() {
				uni.navigateBack();
			},
			/**
			 * 提交
			 */
			onAddClick() {

				this.$refs.mobileApplyInfoRef.validate((valid) => {
					console.log(valid);

					if (!valid) return;

					let params = {
						studentInfoDto: {
							// userId: uni.getStorageSync('userId'),
							name: this.formData.name,
							classId: this.formData.classId,
							jobTitle: this.formData.jobTitle,
							officerId: this.formData.officerId,
							phone: this.formData.phone,
						}
					};

					StudentInfoController.add(this, params).then(res => {
						// showMessage('提交成功', 'success');
						this.show = true;
						if (res) {
							this.content="提交成功"
						}else{
							this.content="提交失败"
						}
						// this.$emit('submit');
						// this.onCancel(true);
					}).catch(e => {});
				});
			},

		},
		computed: {

		},
		mounted() {
			this.loadClassIdDropdownList();
			this.loadGanbuDropdownList();
			// if (this.$refs.mobileApplyInfoRef) this.$refs.mobileApplyInfoRef.setRules(this.rules);
		}
	};
</script>

<style scoped></style>